. paths.conf

search_mod() {
	CACHE=$(mktemp -p ${DL_CACHE})
	find ${MOD_META_STORE} -type f > ${CACHE}
	while read -r line; do
		for optstr in $@; do
			opt=$(echo $optstr | cut -f1 -d'=')
			optarg=$(echo $optstr | cut -f2 -d'=')

			sed -n "/${opt}/{n;p}" $line | grep -i ${optarg} > /dev/null
			if [ $? -ne 0 ]; then
				sed -i "/$(echo $line | sed 's:/:\\\/:g')/d" ${CACHE}
			fi
		done
	done < ${CACHE}
	cat ${CACHE}
}

call_mod() {
	echo $@
	MOD_NAME=${MOD_META_STORE}/${1}
	MOD_BIN=${MOD_STORE}/${1}
	VARNAMES="$(sed -n '/VARIABLES/{n;p}' ${MOD_NAME} | tr ',' ' ' | tr '[[:lower:]]' '[[:upper:]]')"
	for var in ${VARNAMES}; do
		VARNAME=$(grep ${var} ${VAR_STORE}/${1})
		if [ $? -ne 0 ]; then
			echo "${var} not defined"
			echo "mod will not start"
			return 1
		else
			eval "export ${VARNAME}"
		fi
	done
	# pass all paths
	while read -r path; do
		[ "$(echo $path | cut -c1)" = '#' ] && continue
		eval export $path
	done < ./paths.conf
	# pass arguments
	shift
	for var in $@; do
		eval "export ${var}"
	done

	if [ -f ${MOD_BIN} ]; then
		if [ -x ${MOD_BIN} ]; then
			${MOD_BIN} $@
		else
			echo "can not execute module"
		fi
	else
		echo "could not find module binary"
	fi
}
